package 枚举与尺聚法;

import java.util.Scanner;
import java.util.Stack;

public class 公平抽签 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();

        String[] name = new String[n];
        for (int i = 0; i < n; i++) {
            name[i] = scanner.next();
        }
        Stack<String> linkedList = new Stack();
        dfs(name, linkedList, m, 0);
    }

    private static void dfs(String[] name, Stack<String> linkedList, int m, int start) {
        if (linkedList.size() == m) {
            for (String s : linkedList) {
                System.out.print(s + " ");
            }
            System.out.println();
            return;
        }

        for (int j = start; j < name.length; j++) {

            if (m - linkedList.size() > name.length - j + 1) continue; //剪枝
            linkedList.push(name[j]);
            dfs(name, linkedList, m, j + 1);
            linkedList.pop();
        }
    }
}

